﻿using Medianamik.Core.Configuration;
using NUnit.Framework;
using Medianamik.UI.Controls;

namespace Medianamik.Tests.Integration.Medianamik.UI.Controls
{
    [TestFixture]
    public class EditorTest
    {
        [Test]
        public void editor_maxuploadfilesize_should_be_equal_to_the_value_specified_in_the_configuration_file()
        {
            var config = ConfigureMaxUploadFileSize(5000);
            
            var editor = new Editor(config);

            Assert.That(editor.MaxUploadFileSize, 
                        Is.EqualTo(config.EditorMaxUploadFileSize));
        }

        [Test]
        [Ignore]
        public void editor_dialogs_should_have_maxUploadFileSize_Equal_to_Editor_MaxUploadFileSize_after_control_hierarchy_is_created()
        {
            var config = ConfigureMaxUploadFileSize(1234567);
            var testEditor = new TestEditor(config);
            
            testEditor.CreateControlHierarchy();

            Assert.That(testEditor.RadEditor.ImageManager.MaxUploadFileSize,
                        Is.EqualTo(config.EditorMaxUploadFileSize));
            Assert.That(testEditor.RadEditor.FlashManager.MaxUploadFileSize,
                        Is.EqualTo(config.EditorMaxUploadFileSize));
            Assert.That(testEditor.RadEditor.DocumentManager.MaxUploadFileSize,
                        Is.EqualTo(config.EditorMaxUploadFileSize));
            Assert.That(testEditor.RadEditor.MediaManager.MaxUploadFileSize,
                        Is.EqualTo(config.EditorMaxUploadFileSize));
        }

        private MedianamikConfigSection ConfigureMaxUploadFileSize(int maxUploadFileSize)
        {
            var config = new MedianamikConfigSection();
            config.EditorMaxUploadFileSize = maxUploadFileSize;
            return config;
        }

        public class TestEditor : Editor
        {
            public TestEditor(MedianamikConfigSection config)
                :base(config)
            {
            }

            public void CreateControlHierarchy()
            {
                CreateControlHierarchy(false);
            }
        }
    }
}